package com.ssm.Dao;

import com.ssm.Utils.DBCPUtils;

import java.sql.ResultSet;
import java.sql.SQLException;

public class moveShopDao {

    public boolean move(String name,String place,String pic,String username){
        String sql_having="select * from myfavorites where picture=? and username=?";
        String sql="insert into myfavorites(name,place,picture,username) values(?,?,?,?)";
        Object[] objects1={pic,username};
        Boolean b=true;
        ResultSet resultSet = DBCPUtils.executeQuery(sql_having, objects1);

        try {
            while (resultSet.next()){
                b=false;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            //关闭数据库的方法
            DBCPUtils.closeAll(resultSet, DBCPUtils.pstmt, DBCPUtils.connection);
        }
        Object[] objects2={name,place,pic,username};

        if(b){
            b = DBCPUtils.executeUpdate(sql, objects2);
        }

        return b;
    }
}
